<?php
if (!$_SESSION["loggedin"]){
  header("Location: ?q=login");
}

$students = simplexml_load_file('data/student.xml');
$fieldnames = $students->student[0]->children();

if ($args[1] == "cr" && (Util::IsPInt($args[2]) || $args[2] == 0)){
  $tmp = $students->xpath("//student");
  $s = $tmp[$args[2]];
  $reminders = simplexml_load_file('data/reminders.xml');
  $index = count($reminders->xpath("//reminder"));
  $new_node = $reminders->addChild("reminder");
  $new_node["user"] = $_SESSION["username"];
  $new_node["status"] = "deleted";
  foreach ($s->children() as $field) {
    $new_node->addChild($field->getName(), $field);
  }
  
  $dom = new DOMDocument('1.0');
  $dom->preserveWhiteSpace = false;
  $dom->formatOutput = true;
  $dom->loadXML($reminders->asXML(), LIBXML_NOBLANKS);
  $dom->save("data/reminders.xml");
  
  //$reminders->asXML("data/reminders.xml");
  header("Location: ?q=reminders/create/$index");
}

if (isset($_POST["filter"])){
  $class = "";
  if ($_POST["FR"] == "on")
    $class .= "FR";
  if ($_POST["SO"] == "on")
    $class .= "SO";
  if ($_POST["JR"] == "on")
    $class .= "JR";
  if ($_POST["SR"] == "on")
    $class .= "SR";
  $alpha = $_POST["alpha1"] ."". $_POST["alpha2"];
  
  User::GetUser()->SavePreferences($class, $alpha);
}

?>